package _4_8;

import java.util.ArrayList;

public class SchoolClass {
	private static char nextClassId = 'a';
	private String id;
	private int nextStudentId;
	private ArrayList<Student> students;
	private ArrayList<Teacher> teachers;

	public SchoolClass () {
		this.id = "" + SchoolClass.nextClassId++;
		this.students = new ArrayList<Student> ();
		this.teachers = new ArrayList<Teacher> ();
		this.nextStudentId = 1;
	}

	public SchoolClass (String id) {
		this.id = id;
		this.students = new ArrayList<Student> ();
		this.teachers = new ArrayList<Teacher> ();
		this.nextStudentId = 1;
	}

	public void addStudent (String name) {
		this.students.add (new Student (name, this.nextStudentId++));
	}

	public void addTeacher (Teacher t) {
		this.teachers.add (t);
	}

	public int getNStudents () {
		return this.students.size ();
	}

	public int getNTeachers () {
		return this.teachers.size ();
	}

	public Student[] getStudents () {
		return (Student[]) students.toArray ();
	}

	public Teacher getTeacherAt (int i) {
		try {
			return teachers.get (i);
		} catch (IndexOutOfBoundsException e) {
			return null;
		}
	}

	public Teacher[] getTeachers () {
		return (Teacher[]) teachers.toArray ();
	}

	public void print () {
		System.out.println ("Class " + id + " :");

		System.out.println ("\nTeachers:");
		for (Teacher t : teachers) {
			t.print ();
		}

		System.out.println ("\nStudents:");
		for (Student s : students) {
			s.print ();
		}

		System.out.println ("\n");
	}

	public boolean removeStudentAt (int i) {
		try {
			this.students.remove (i);
			return true;
		} catch (IndexOutOfBoundsException e) {
			return false;
		}
	}

	public boolean removeTeacherAt (int i) {
		try {
			this.teachers.remove (i);
			return true;
		} catch (IndexOutOfBoundsException e) {
			return false;
		}
	}
}
